package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.Question;

public class QuestionDao extends SuperDao {

	/**
	 * 
	 *查询问题
	 */
	public List<Object> watchQuestions(Question question) {
		String hql = "from Question where eaId = ?";
		Object[] values = new Object[] { question.getEaId() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 * 保存问题
	 */
	public void saveQuestion(Question question) {
		super.save(question);
	}

	/**
	 * 
	 * 通过id查询问题
	 */
	public List<Object> getOneQuestion(Question question) {
		String hql = "from Question where id = ?";
		Object[] values = new Object[] { question.getId() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 * 修改问题
	 */
	public void modifyQuestion(Question question) {
		/*String sql = "update b_question set content = '"
				+ question.getContent() + "', searchType = "
				+ question.getSearchType() + ", rely_id = "
				+ question.getRelyId() + ", type = " + question.getType()
				+ " where id = " + question.getId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb = new StringBuilder();
		sb.append("update b_question set content = '");
		sb.append(question.getContent());
		sb.append("', searchType = ");
		sb.append(question.getSearchType());
		sb.append(", rely_id = ");
		sb.append(question.getRelyId());
		sb.append(", type = ");
		sb.append(question.getType());
		sb.append(" where id = ");
		sb.append(question.getId());
		super.executeUpdate(sb.toString());
	}

	/**
	 * 
	 * 删除问题
	 */
	public void delQuestion(Question question) {
		super.delete(question);
	}
	
	/**
	 * 
	 *通过replyId查询问题
	 */
	public List<Object> findQuestionsByReplyId(Question question) {
		String hql = "from Question where eaId = ? and relyId = ?";
		Object[] values = new Object[] { question.getEaId(), question.getRelyId() };
		return super.getObject(hql, values);
	}
}
